/*
 * BncsMessageFactory.cpp
 *
 *  Created on: Nov 20, 2008
 *      Author: nathan
 */

#include "BncsMessageFactory.h"

/* No need to worry about thread-safety here.
 * This is always called during static initialization.
 */
BncsMessageFactoryRegistrar::BncsMessageFactoryRegistrar(int id, BncsMessage* msg)
{
	BncsMessageFactory::msgTable.insert(id, msg);
}

/* This only reads from the hash table, so it is thread-safe. */
BncsMessage* BncsMessageFactory::newMessage(int id)
{
	if (!msgTable.contains(id))
	{
		return NULL;
	}

	BncsMessage* msg = msgTable.value(id)->clone();

	return msg;
}
